<?php

$rootdir = '../';
include_once('session.php');

global $desql;
$desql->Connect();

function CreateCollectionImage($NomFichier, $Categorie)
{
	global $desql;
	
	$result = $desql->Query('INSERT INTO imagescollection(nomfichier, categorie) 
										VALUES(\''. mysql_real_escape_string($NomFichier) . '\',
												\''. mysql_real_escape_string($Categorie) . '\'
												)');
	return $result;
}

function GetAllCollectionImages()
{
	global $desql;
	$images = array();
	
	$answer = $desql->Query('SELECT * FROM imagescollection');
	if($answer == false)
		return false;
		
	while($image = mysql_fetch_array($answer))
		$images[$image['id']] = $image;
	
	return $images;
}

function DeleteCollectionImageById($Id)
{
	global $desql;
	
	if(is_numeric($Id) == false)
		return false;
	else
		return $desql->Query('DELETE FROM imagescollection WHERE id=' . $Id);
}

function GetAdminCollectionHTMLContent()
{
	$HTML = '<div style="margin-top: 20px; margin-left: 20px;">';
		
	$HTML .= '
		<table style="font-size: 80%; width: 90%; text-align: center;">
			<tr>
				<th style="border: 1px solid gray;">Nom</th>
				<th style="border: 1px solid gray;">Catégorie</th>
				<th style="border: 1px solid gray;">Options</th>
			</tr>
			<tr>
				<td  style="border: 1px solid gray;"></td>
				<td  style="border: 1px solid gray;"></td>
				<td  style="border: 1px solid gray;"><div id="icone-nouveau"><a href="cadre_admin.php?type=6&new=1"></a></div></td>
			<tr>' . GetAdminImageHTMLContent() . '
		</table>
	';
	return $HTML . '</div>';
}

function GetAdminImageHTMLContent()
{
	$images = GetAllCollectionImages();
	$HTML = '';
	
	if($images == false)
		return '';
	
	foreach($images as $image)
	{
		$HTML .= '
			<tr>
				<td style="border: 1px solid gray;"><img width=400 src="images_collection/' . $image['nomfichier'] . '" /></td>
				<td style="border: 1px solid gray;">' . $image['categorie'] . '</td>
				<td style="border: 1px solid gray;">
					<div id="icone-supprimer">
						<a href="cadre_admin.php?type=6&deleteid=' . $image['id'] . '" onClick="return(confirm(\'Etes-vous sûr de vouloir supprimer cette image?\'));"></a>
					</div>
				</td>
			</tr>
		';
	}

	return $HTML;
}

function GetCreateCollectionImageForm()
{
	$HTML = '
		<h4>Nouvelle image</h4>
		<form enctype="multipart/form-data" style="margin-left: 20px; margin-top: 20px; font-size: 80%;" method="post">
			<br />
			<table style="margin: auto;">
				<tr>
					<td style="width: 150px;"><label for="collectionimage">Fcihier :</label></td>
					<td><input type="file" tabindex="1" name="collectionimage" size="30" /><br /></td>
				</tr>
				<tr>
					<td><label for="categorie">Catégorie :</label></td>
					<td>
						<select tabindex="2" name="categorie" id="categorie">
							<option value="club">Le club</option>
							<option value="atelier">L\'atelier</option>
						</select>
					</td>	
				</tr>
				<tr>
					<td></td>
					<td><br /><input type="submit" name="send" tabindex="3" value="Envoyer" /></td>
				</tr>
			</table>
		</form>
	';
	
	return $HTML;
}

?>